import request from "@/utils/request";

export interface getCategoryItemType {
  id: number;
  name: string;
  category1Id?: number;
  category2Id?: number;
}

export type getCategoryType = getCategoryItemType[];

//1.请求一级分类列表
export const getCategoryRequest1 = () => {
  return request.get<any, getCategoryType>(`/admin/product/getCategory1`);
};

//2.请求二级分类列表
export const getCategoryRequest2 = (category1Id: number) => {
  return request.get<any, getCategoryType>(
    `/admin/product/getCategory2/${category1Id}`
  );
};

//3.请求三级分类列表
export const getCategoryRequest3 = (category2Id: number) => {
  return request.get<any, getCategoryType>(
    `/admin/product/getCategory3/${category2Id}`
  );
};


//某个属性内属性值列表的类型
export interface getAttrListType {
  id? : number;
  valueName : string;
  attrId : number | undefined
  isEdit?:boolean 
}

//某个属性的类型
export interface getAttrItemType {
  id?: number;
  attrName: string;
  categoryId: number;
  categoryLevel: number;
  attrValueList:getAttrListType[];
  attrIdValueId?:string;
}

export type getAttrReturnType = getAttrItemType[]

//请求当前三级列表的数据
export const getAttrListRequest = (category1Id:number,category2Id:number,category3Id:number) => {
  return request.get<any,getAttrReturnType>(`/admin/product/attrInfoList/${category1Id}/${category2Id}/${category3Id}`)
}

//根据attrId删除
export const getDeleteAttrRequest = (attrId:number) => {
  return request.delete<any,null>(`/admin/product/deleteAttr/${attrId}`)
}

//新增或修改请求
export const getAddOrUpRequest = (attrParams:getAttrItemType) => {
  return request.post<any,null>(`/admin/product/saveAttrInfo`,attrParams)
}
